<template>
  <el-row>
    <el-col :span="12">
      <el-select
        size="mini"
        v-model="data.identifier"
        @change="conditionChange"
      >
        <el-option-group
          v-for="group in items"
          :key="group.name"
          :label="group.name"
        >
          <el-option
            v-for="pro in group.items"
            :label="pro.name"
            :value="pro.identifier"
            :key="pro.identifier"
          ></el-option>
        </el-option-group>
      </el-select>
    </el-col>
    <el-col :span="6">
      <el-select size="mini" v-model="data.comparator">
        <el-option
          v-for="cp in compares"
          :label="cp.name"
          :value="cp.value"
          :key="cp.value"
        ></el-option>
      </el-select>
    </el-col>
    <el-col :span="4">
      <el-input size="mini" v-model="data.value" auto-complete="off"></el-input>
    </el-col>
  </el-row>
</template>

<script>
export default {
  name: "FilterPropCondition",
  props: {
    data: {
      type: Object,
      default: () => {
        return {
          device: "",
          type: "property",
          identifier: "",
          value: "",
          comparator: "",
        };
      },
    },
    items: {
      type: Array,
      default: () => {
        return [];
      },
    },
  },
  data() {
    return {
      inEdit: false,
      compares: [
        {
          name: "大于",
          value: ">",
        },
        {
          name: "等于",
          value: "==",
        },
        {
          name: "小于",
          value: "<",
        },
        {
          name: "不等于",
          value: "!=",
        },
        {
          name: "包含",
          value: "in",
        },
        {
          name: "不包含",
          value: "notin",
        },
        {
          name: "相似",
          value: "like",
        },
      ],
    };
  },
  // 注册组件
  components: {},
  created() {},
  methods: {
    conditionChange() {
      this.items.forEach((g) => {
        g.items.forEach((i) => {
          if (i.identifier == this.data.identifier) {
            this.data.type = i.type;
            return;
          }
        });
      });
    },
  },
};
</script>
